//
//  OneCartoonViewController.m
//  CRSCMOA
//
//  Created by goldnut on 16/8/31.
//  Copyright © 2016年 王文晓. All rights reserved.
//

#import "OneCartoonViewController.h"
#import "OneCartoonableViewCell.h"
#import "RechargeDetailsViewController.h"

@interface OneCartoonViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UILabel *balanceLabel;
@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) NSString *cardBalance;
@end

@implementation OneCartoonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //    [self setUpNavgationBar];
    [self.view addSubview:self.tableView];
    
    
    //POST请求
    NSDictionary *mdic = [NSDictionary dictionaryWithObjectsAndKeys:[CurrentUserInfo sharedCurrentUserInfo].uid,@"uid",nil];
    [JNTDataRequestTools getFetchDataWithUrlString:OneCartoon_URl paramenters:mdic
                                           success:^(id data) {
                                               // 请求成功，解析数据
                                               NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
                                               
                                               self.cardBalance = resultDic[@"cardBalance"];
                                               
                                               self.moneyLabel.text = [NSString stringWithFormat:@"%@",self.cardBalance];
                                               
                                           } fail:^{
                                               
                                               NSLog(@"话题列表请求失败");
                                           } view:self.view];
    
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
        OneCartoonableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleLabel.text = self.titleArray[indexPath.row];
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     if (indexPath.row == 0) {
    RechargeDetailsViewController *rechargeVC = [[RechargeDetailsViewController alloc]init];
    //rechargeVC.title = self.titleArray[indexPath.row];
    [self.navigationController pushViewController:rechargeVC animated:YES];
     }
}




#pragma mark - 设置导航条
- (void)setUpNavgationBar
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"上栏"] forBarMetrics:UIBarMetricsDefault];
    self.navigationItem.title = @"一卡通";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
}


#pragma mark ---视图初始化--
-(UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:kRect(0, 210, kScreenWidth, kScreenHeight-220) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
        _tableView.backgroundColor = [UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1.0];
        [_tableView registerNib:[UINib nibWithNibName:@"OneCartoonableViewCell" bundle:nil] forCellReuseIdentifier:@"CELL"];
    }
    return _tableView;
}


- (NSArray *)titleArray {
    
    if (!_titleArray) {
        
        _titleArray = [NSArray arrayWithObjects:@"充值记录",@"消费记录", nil];
    }
    return _titleArray;
}






@end
